﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.UI;

public static class UnityCoreExtension
{
    #region Array

    public static string ArrayToString<T>(this T[] array, string joinStr = ", ")
    {
        int count = array.Length;
        string rst = "";
        for (int i = 0; i < count; i++)
        {
            rst += array[i].ToString();
            if (i != count - 1)
            {
                rst += joinStr;
            }
        }

        return rst;
    }

    #endregion

    #region List

    /// <summary>
    /// Add value to list if not contain.
    /// </summary>
    public static void AddIfNotContain<T>(this List<T> list, T value)
    {
        if (!list.Contains(value))
        {
            list.Add(value);
        }
    }

    public static string ListToString<T>(this List<T> list, string joinStr = ", ")
    {
        int count = list.Count;
        string rst = "";
        for (int i = 0; i < count; i++)
        {
            rst += list[i].ToString();
            if (i != count - 1)
            {
                rst += joinStr;
            }
        }

        return rst;
    }

    public static bool IsListEqual<T>(this List<T> thisList, List<T> otherList)
    {
        if (thisList == null || otherList == null)
            return thisList == null && otherList == null;

        if (thisList.Count != otherList.Count)
            return false;

        foreach (var i in thisList)
            if (!otherList.Contains(i))
                return false;

        return true;
    }

    #endregion
}